home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / text / diskfont.txt < prev    next >
Text File  |  1986-01-07  |  4KB  |  82 lines

  1.  
  2. TITLE:Disk Font System BUG!
  3.  
  4. There is a bug in the V1.0 and V1.1 diskfont.library code that can cause
  5. the system to crash when memory gets low.  A workaround is presented
  6. below.
  7.  
  8. Disk based system resources such as fonts and device drivers are brought
  9. in to memory when they are first opened.  They remain in memory thereafter
  10. until some task asks for more memory than is available in the system
  11. free memory pool.  At that point the EXEC function AllocMem() "expunges"
  12. (removes from memory) any such resources which currently have zero
  13. openers.  This design means that resources tend to hang around in memory
  14. so that if they are frequently opened and closed there is no time lost
  15. reloading them from the disk.
  16.  
  17. Many applications periodically use the trick of attempting to AllocMem()
  18. more memory than can possibly be in the system to flush any unused
  19. resources from memory.  Note that if AllocMem() finds any resources to
  20. expunge, then the number returned by AvailMem() AFTER the call to AllocMem()
  21. will be larger than before the call (presuming of course that the
  22. AllocMem() does not, in fact, return a newly allocated chunk of memory
  23. to you).
  24.  
  25. The bug is that when a disk based font is expunged from memory, the
  26. expunge code in diskfont.library does not properly remove the font
  27. descriptor from the list of fonts known to be in memory.  Thereafter,
  28. whenever a font is looked-up, there is a chance that the system will
  29. crash since the font node now points at memory that has been returned
  30. to the system free pool.
  31.  
  32. The workaround involves manually removing the font from the font list
  33. before you close it.  The workaround, as presented, provides maximum
  34. protection for the system at the expense of possibly having multiple
  35. copies of the font temporarily exist in memory together.  If you know
  36. that ALL font users in the system are using the workaround, then only
  37. the last closer of the font need do the Remove() function.  Note that
  38. the V1.1 version of Notepad (for instance) does NOT implement this
  39. workaround.
  40.  
  41. The workaround for the diskfont.library bug is, whenever closing a font:
  42. 1)  Forbid();
  43. 2)  check the font flags to see if it is a disk font
  44. 3)      if a disk font, check that this font is in a list by ensuring that the
  45.         predecessor's and successor's nodes point to it.
  46. 4)          if the font is in a list, Remove(0, font) it.
  47. 5)  Permit();
  48. 6)  CloseFont();
  49.  
  50. Note that the first argument to Remove(), the 0, is a dummy argument
  51. present for historical purposes.
  52.  
  53. The TextFont structure is described in the include file text.h (or text.i
  54. if you speak assembly).  Note that the Accessors field contains the
  55. opener count for a font.
  56.  
  57. If you are not concerned with reclaiming the memory space taken up by
  58. your unused fonts, it is sufficient, as an alternate workaround, simply
  59. to never close your fonts.  This will insure that AllocMem() never
  60. tries to expunge the font.  Note that this would keep the font from
  61. EVER going away -- even after your program terminates.
  62.  
  63. If Notepad, or another program, has opened and closed disk fonts prior to
  64. the running of your program, the font list has the potential of
  65. being messed up the next time AllocMem() goes to expunge resources.
  66. If such an expunge has already occurred, there is no recovery other
  67. than to reboot the system.  On the other hand, if an expunge has NOT
  68. yet occurred, you can protect yourself by emptying the font list before
  69. you first trigger an expunge.  To empty the font list, traverse it
  70. starting from the TextFonts pointer found in the structure GfxBase.  Do
  71. a Remove() on each disk based font in the list (WARNING!  Only Remove()
  72. disk based fonts).  The elements of the list are structures of the
  73. type TextFont.  Note that you MUST do this cleanup prior to triggering
  74. your first expunge (i.e., before calling AllocMem() with a large
  75. value).  This cleanup should be done while tasking is disabled (i.e.,
  76. between a Forbid() and a Permit()).
  77.  
  78. This bug will be fixed in the V1.2 system software.  Any application
  79. implementing the above workaround will continue to work under the new
  80. system software.
  81.  
  82.